﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MyGeneration.dOOdads;
using MethodIT.Helper;

using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web.ZB
{
    public partial class PreviewAppraisal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnPrint.Attributes.Add("onclick", "excel();");

            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            int nTypeID = HelperURL.GetIntFromUrlString("TypeID");
            LoadData(nKpID,nTypeID);

        }

        private void LoadData(int nKpID,int nTypeID)
        {
            KP_Template vw = new KP_Template();
            vw.Where.KP_ID.Value = nKpID;
            vw.Query.Load();

            bool IsShow = nTypeID.Equals(1);
            p1.Controls.Add(CreateTable(nKpID, IsShow));
        }

        public Table CreateTable(int nKpID, bool IsShow)
        {
            //创建表头
            Table tb = new Table();
            TableRow tr = new TableRow();
            TableCell tc = new TableCell();

            //tb.Attributes.Add("style", zTable.TableStyle);
            tb.Attributes.Add("border", "1");
            //tb.Attributes.Add("class", "ms-formlabel");
            tb.Attributes.Add("width", "100%");
            tb.Attributes.Add("cellpadding", "0");
            tb.Attributes.Add("cellspacing", "0");

            //得到表名称
            KP_Master kp = new KP_Master();
            kp.LoadByPrimaryKey(nKpID);

            tr = new TableRow();
            tc = HelperTable.CreateStyleCell(1, 7, kp.Title, "font-size: 18.0pt;font-weight: 700;font-style: normal;text-decoration: none;font-family: 黑体;text-align: center;vertical-align: middle;white-space: normal;");
            tr.Cells.Add(tc);
            tb.Rows.Add(tr);

            tr = new TableRow();
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "序号"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "评议指标"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "指标内容"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "具体要求"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "分值"));
            tr.Cells.Add(HelperTable.CreateCell(1, 1, "投标人"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "评分细则"));

            tb.Rows.Add(tr);

            //表头投标公司
            tr = new TableRow();
            tr.Cells.Add(HelperTable.CreateCell(1, 1, "T1","ms-header"));
            tb.Rows.Add(tr);

            //得到总指标数量 nItemCount
            KP_Template template = new KP_Template();
            template.Where.KP_ID.Value = nKpID;
            template.Where.Is_Group.Value = 0;
            template.Query.Load();
            int nItemCount = template.RowCount;

            //得到 指标集数量nGroupCount
            template = new KP_Template();
            template.Where.KP_ID.Value = nKpID; 
            template.Where.Is_Group.Value = 1;
            template.Query.Load();
            int nGroupCount = template.RowCount;

            int RowNo = 1;

            tr = new TableRow();

            tr.Cells.Add(HelperTable.CreateCell(nItemCount, 1, (RowNo++).ToString()));
            tr.Cells.Add(HelperTable.CreateCell(nItemCount, 1, "得分"));

            //添加指标集
            while (!template.EOF)
            {
                KP_Template itemTemplate = new KP_Template();
                itemTemplate.Where.Parent_Item_ID.Value = template.Item_ID;
                itemTemplate.Query.Load();
                tc = HelperTable.CreateCell(itemTemplate.RowCount, 1, "&nbsp;");
                //tc.Controls.Add(new LiteralControl(template.Item_Name + "(权重" + (template.Item_Quotiety * 100).ToString() + "%)"));
                tc.Controls.Add(new LiteralControl(template.Item_Name));//
                tr.Cells.Add(tc);

                //添加指标项目
                while (!itemTemplate.EOF)
                {
                    //tr.Cells.Add(HelperTable.CreateCell(1, 1, itemTemplate.Item_Name + "(权重" + (itemTemplate.Item_Quotiety * 100).ToString() + "%)"));
                    tr.Cells.Add(HelperTable.CreateCell(1, 1, itemTemplate.Item_Name));
                    tr.Cells.Add(HelperTable.CreateCell(1, 1,itemTemplate.Max_Score.ToString("N2") ));
                    //添加指标项目填分框                    
                    tc = HelperTable.CreateCell(1, 1, "&nbsp;");
                    if (!IsShow)
                    {
                        TextBox txtItem = new TextBox();
                        int ItemWidth = itemTemplate.Item_Width;

                        txtItem.ID = "ITEM_CTRL_PREID_" + itemTemplate.Item_ID.ToString() ;
                        txtItem.Width = Unit.Pixel(ItemWidth);
                        if (itemTemplate.Item_Type.Equals("1"))
                        {
                            txtItem.TextMode = TextBoxMode.MultiLine;
                            txtItem.Height = Unit.Pixel(54);
                        }

                        tc.Controls.Add(txtItem);
                    }
                    tr.Cells.Add(tc);

                    // 指标项评分描述
                    tc = new TableCell();
                    tr.Cells.Add(HelperTable.CreateCell(1, 1, itemTemplate.Item_Desc.Equals("") ? "&nbsp;" : itemTemplate.Item_Desc));
                    //tc.Text = itemTemplate.Item_Desc.Equals("") ? "&nbsp;" : itemTemplate.Item_Desc;
                    tr.Cells.Add(tc);

                    tb.Rows.Add(tr);
                    tr = new TableRow();

                    itemTemplate.MoveNext();
                }

                template.MoveNext();
            }

            //表脚
            tr = new TableRow();
            tr.Cells.Add(HelperTable.CreateCell(1, 5, "总分"));
            tc = HelperTable.CreateCell(1, 1, "&nbsp;");
            tr.Cells.Add(tc);

            tr.Cells.Add(HelperTable.CreateCell(1, 1, "按权重汇总分数"));
            tb.Rows.Add(tr);

            return tb;
        }
    }
}
